<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/res/layui/css/layui.css" media="all">
    <style>
        .layui-form-checkbox span {
            line-height: 14px;
            color: #666;
            font-size: 14px;
        }
    </style>
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: #FF5722">*</span> 商户名称</label>
        <div class="layui-input-block">
            <input type="text" name="username" lay-verify="required" placeholder="请输入商户名称" lay-reqtext="请输入商户名称" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: #FF5722">*</span> 手机号</label>
        <div class="layui-input-block">
            <input type="text" name="cellphone" lay-verify="required" placeholder="请输入手机号" lay-reqtext="请输入手机号" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: #FF5722">*</span> 邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="email" lay-verify="required" placeholder="请输入邮箱" lay-reqtext="请输入邮箱" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: #FF5722">*</span> 密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: #FF5722">*</span> 确认密码</label>
        <div class="layui-input-block">
            <input type="password" name="confirm_password" lay-verify="required" placeholder="请输入确认密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: #FF5722">*</span> 角色 </label>
        <div class="layui-input-block" id="role_ids">

        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">企业</label>
        <div class="layui-input-block">
            <select name="enterprise_id" lay-search="">
                <option value="">直接选择或搜索选择</option>
                {foreach $enterprises as $enterprise}
                <option value="{$enterprise['id']}">{$enterprise['name']}</option>
                {/foreach}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态 <span style="color: #FF5722">*</span></label>
        <div class="layui-input-block">
            <input type="checkbox" lay-verify="required" checked lay-filter="status" name="status" lay-skin="switch" lay-text="启用|禁用" value="1">
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
</div>

<script>
    var MERCHANT_DO_ADD_URL='{:url("merchant/doAdd")}';
</script>
<script src="__STATIC__/res/layui/layui.js"></script>
<script>
    layui.config({
        base: '__STATIC__/res/' //静态资源所在路径
    }).use(['index', 'form','selectM'], function(){
        var $ = layui.$
            ,form = layui.form
            ,selectM = layui.selectM;

        //多选标签-基本配置
        selectM({
            //元素容器【必填】
            elem: '#role_ids'
            //候选数据【必填】
            ,data: JSON.parse('{$roles|raw}')
            ,max:5
            // ,width:400
            //添加验证
            ,verify:'required'
        });

        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function(data){
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                method: 'post',
                data: field,
                url: MERCHANT_DO_ADD_URL,
                success: function (res) {
                    if (res.result.status) {
                        layer.msg(res.result.msg, {
                            offset: '15px'
                            , icon: 2
                            , time: 1000
                        });
                        return
                    }
                    parent.layui.table.reload('LAY-app-content-list'); //重载表格
                    parent.layer.close(index); //再执行关闭
                }
            });
        });
    })
</script>
</body>
</html>